package com.machinecontroller.adapter;

import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.TextView;

import com.machinecontroller.R;
import com.machinecontroller.model.ManagerModel;
import com.tencent.bugly.beta.Beta;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zhangxuehui on 2017/12/12.
 */

public class ManagerAdapter extends BaseAdapter {
    private Context mContext;
    private List<ManagerModel> mList;
    private LayoutInflater mInflater;
    private String mContainerNum;//货柜号

    public ManagerAdapter(Context context, List<ManagerModel> list) {
        this.mContext = context;
        this.mList = list;
        this.mInflater = LayoutInflater.from(context);
    }


    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int i) {
        return mList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    public String getContainerNum() {
        return mContainerNum;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder mHolder;
        if (view == null) {
            view = mInflater.inflate(R.layout.item_name_edit, viewGroup, false);
            mHolder = new ViewHolder(view);
            view.setTag(mHolder);
        } else {
            mHolder = (ViewHolder) view.getTag();
        }
        mHolder.mTvName.setText(mList.get(i).getName());
        mHolder.mEtContent.setText(mList.get(i).getContent());
        if (!mList.get(i).isInput()) {
            mHolder.mEtContent.setOnKeyListener(null);
        }
        if (mList.get(i).getId() == 2) {
            mContainerNum = mList.get(i).getContent();
        }
        if(mList.get(i).getId()==8){
            view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Beta.checkUpgrade();
                }
            });
        }
        return view;
    }

    public static class ViewHolder {
        View view;
        TextView mTvName;
        EditText mEtContent;

        ViewHolder(View view) {
            this.view = view;
            this.mTvName = (TextView) view.findViewById(R.id.tv_name);
            this.mEtContent = (EditText) view.findViewById(R.id.et_content);
        }
    }
}
